import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { IPage, IResource } from "./types";

/* 查询资源列表 */
export function getPageResourceAPI(
  queryParams?: IPage
): AxiosPromise<PageResult<IResource[]>> {
  return request({
    url: "/resource/page",
    method: "get",
    params: queryParams,
  });
}

/* 查询资源列表 */
export function getListResourceAPI(): AxiosPromise<IResource[]> {
  return request({
    url: "/resource/list",
    method: "get",
  });
}

/* 根据id查询资源对象 */
export function getFormResourceAPI(id: number): AxiosPromise<IResource> {
  return request({
    url: `/resource/${id}/form`,
    method: "get",
  });
}

/**
 * 添加资源
 *
 * @param data
 */
export function addResourceAPI(data: any) {
  return request({
    url: "/resource",
    method: "post",
    data: data,
  });
}

/**
 * 修改资源
 *
 * @param id
 * @param data
 */
export function updateResourceAPI(id: number, data: IResource) {
  return request({
    url: "/resource/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除资源
 *
 * @param ids
 */
export function deleteResourceAPI(ids: number) {
  return request({
    url: "/resource/" + ids,
    method: "delete",
  });
}

/* 获取预约申请 */
export function getPageResourceApplicationAPI(
  queryParams?: IPage
): AxiosPromise<PageResult<IResource[]>> {
  return request({
    url: "/resource/application/page",
    method: "get",
    params: queryParams,
  });
}

export function overruleAPI(data: IResource) {
  return request({
    url: "/resourceRecord/overrule",
    method: "put",
    data: data,
  });
}

export function passAPI(id: number) {
  return request({
    url: "/resourceRecord/pass/" + id,
    method: "get",
  });
}

export function cancelAPI(id: number) {
  return request({
    url: "/resourceRecord/cancel/" + id,
    method: "get",
  });
}

export function finishAPI(id: number) {
  return request({
    url: "/resourceRecord/finish/" + id,
    method: "get",
  });
}

/* 实验室座位预约 */
export function getResourceStatusdAPI(data: any): AxiosPromise<IResource[]> {
  return request({
    url: `/resource/status`,
    method: "Post",
    data: data,
  });
}
